<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<th:block th:include="common/head :: head('')"/>
<link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css?v=1.18.3}" rel="stylesheet"/>
<link th:href="@{/ruoyi/css/ry-ui.css?v=4.7.7}" rel="stylesheet"/>
<link th:href="@{/css/eUpload.css?v=4.7.7}" rel="stylesheet"/>


<style>
    .index-header-search, .index-header-menus, .index-header-gray {
        display: none;
    }

    .fixed-table-toolbar {
        display: none;
    }

    .app-detail {

    }

    .app-detail .common-block-title {
        height: 60px;
        font-size: 18px;
    }

    .app-detail-content {
        padding: 20px;
        min-height: 155px;
        display: flex;

    }

    .app-detail-logo {
        padding: 0 20px 0 20px;
    }

    .app-detail-logo img {
        width: 60px;
        height: 60px;
    }

    .app-detail-line {
        display: flex;
    }

    .app-detail-line > label {
        color: var(--color);
        width: 90px;
    }

    .app-detail-line > div {

    }

    .app-detail-report {
        min-height: 500px;
        padding: 30px;
    }

    .apk-title {
        font-size: 14px;
        color: #333;
        font-weight: 700;
        margin-bottom: 23px;
    }

    .etable {
        margin: 0;
        width: 100%;
    }

    .etable tr {
        border: 1px solid #e5e5e5;
        border-collapse: collapse;
        word-break: break-all;
        word-wrap: break-word;
        font-size: 14px;
        line-height: 1.5;
    }
    .etable th, .etable td {
        height: 59px;
        padding: 8px 20px;
    }

    .etable th {
        background: #efefef;
        text-align: left;
    }
    .etable th:first-child {
        width: 432px;
        border-right: none;
    }
    .etable th:nth-child(2) {
        width: 278px;
        border-left: none;
    }
    .etable td {
        border: 1px solid #e5e5e5;
        border-collapse: collapse;
    }
    .etable td:first-child {
        border-right: none;
    }
    .red {
        color: #F00;
    }

    #ipa .etable th:first-child {
        width: 20%;
    }
    #ipa .etable th:nth-child(2) {
        width: 20%;
    }

</style>

<body>
<th:block th:include="common/head :: header('/')"/>

<div class="app-detail page-main">
    <div class="common-block-title">
        <img class="common-block-title__ico" src="/img/ico-list1.png"/>
        <span class="common-block-title__txt">基本信息</span>
    </div>
    <div class="app-detail-content common-block-content">
        <div class="app-detail-logo">
            <img src="/img/app_wx.png"/>
        </div>
        <div class="app-detail-more">
            <div class="app-detail-line">
                <label>应用名称：</label>
                <div th:utext="${app.appName}"></div>
            </div>
            <div class="app-detail-line">
                <label>文件大小：</label>
                <div th:utext="${app.size}"></div>
            </div>
            <div class="app-detail-line">
                <label>包名：</label>
                <div th:utext="${app.packName}"></div>
            </div>
            <div class="app-detail-line">
                <label>版本：</label>
                <div th:utext="${app.version}"></div>
            </div>
            <div class="app-detail-line">
                <label>MD5：</label>
                <div th:utext="${app.md5}"></div>
            </div>
            <div class="app-detail-line">
                <label>平台：</label>
                <div th:utext="${app.ext1 == 'apk' ? '安卓' : '苹果'}"></div>
            </div>
        </div>
    </div>


    <div class="common-block-title mt20">
        <img class="common-block-title__ico" src="/img/ico-list1.png"/>
        <span class="common-block-title__txt">扫描报告</span>
    </div>

    <div class="app-detail-report common-block-content">
        <div id="apk" class="detail-inner clearfix" style="display: none;">
            <div class="col-lg-6">
                <div class="apk-title">合规检测</div>
                <table class="etable">
                    <tbody>
                        <tr>
                            <th>检测种类</th>
                            <th>检测结果</th>
                        </tr>
                        <tr><td>病毒检测</td> <td> <span id="virusTest"></span> </td></tr>
                        <tr><td>危险权限检测</td> <td> <span id="dangerTest"></span></td></tr>
                        <tr><td>包含APK文件检测</td> <td><span id="isApkTest"></span></td></tr>
                        <tr><td>证书安全性检测</td> <td><span id="certTest"></span></td></tr>
                        <tr><td>安全性检测</td> <td><span id="saftyTest"></span></td></tr>
                        <tr><td>漏洞与安全风险检测</td> <td><span id="bugTest"></span></td></tr>
                    </tbody>
                </table>
            </div>
            <div class="col-lg-6">
                <div class="apk-title ">安全组件</div>
                <table class="etable">
                    <tbody>
                    <tr>
                        <th>组件检测种类</th>
                        <th>状态</th>
                    </tr>
                    <tr><td>Activity组件暴露检测</td> <td> <span id="activityTest"></span> </td></tr>
                    <tr><td>Service组件暴露检测</td> <td> <span id="serviceTest"></span></td></tr>
                    <tr><td>BroadcastReceiver组件暴露检测</td> <td><span id="broadTest"></span></td></tr>
                    <tr><td>Content Provider组件暴露检测</td> <td><span id="providerTest"></span></td></tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div id="ipa" class="detail-inner clearfix" style="display: none;">
            <div id="ipaTip" style="margin-bottom: 20px; color: var(--color); display: none;">
                <img src="/img/ico_waring.svg" style="margin-right: 10px;"/>
                建议采取对应安全措施后进行投放
            </div>
            <table class="etable">
                <tbody>
                    <tr>
                        <th>检测结果</th>
                        <th>总计</th>
                        <th>高</th>
                        <th>中</th>
                        <th>低</th>
                    </tr>
                    <tr>
                        <td>测试项目数</td>
                        <td><span id="itemTotal"></span></td>
                        <td><span id="item1"></span></td>
                        <td><span id="item2"></span></td>
                        <td><span id="item3"></span></td>
                    </tr>
                    <tr>
                        <td>存在问题项</td>
                        <td><span id="unSafetyTotal"></span></td>
                        <td><span id="unSafety1"></span></td>
                        <td><span id="unSafety2"></span></td>
                        <td><span id="unSafety3"></span></td>
                    </tr>
                    <tr>
                        <td>发现风险数</td>
                        <td><span id="riskTotal"></span></td>
                        <td><span id="risk1"></span></td>
                        <td><span id="risk2"></span></td>
                        <td><span id="risk3"></span></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>


<th:block th:include="common/head :: link"/>
<th:block th:include="common/head :: footer"/>
<script src="/js/me/eUpload.js"></script>


<!-- bootstrap-table 表格插件 -->
<script th:src="@{/js/bootstrap.min.js?v=3.3.7}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js?v=1.18.3}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js?v=1.18.3}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js?v=1.18.3}"></script>
<script th:src="@{/ruoyi/js/ry-ui.js?v=4.7.7}"></script>
<script th:src="@{/ajax/libs/blockUI/jquery.blockUI.js?v=2.70.0}"></script>
</body>
<script th:inline="javascript">
    const id = [[${app.id}]]
    const app = [[${app}]]

    init()

    function init() {
        $('.detail-inner').hide()
        const ext1 = app.ext1
        if (ext1 === 'apk') {
            fillApk()
        } else {
            fillIpa()
        }
    }

    function fillApk() {

        $('#apk').show()

        const json = JSON.parse(app.ext2)
        var obj = null
        if(Object.prototype.toString.call(json) === '[object Array]') {
            obj = json[0]
        } else {
            obj = json
        }
        console.info(obj)
        const Components = obj.report.Components || {}
        const ExportedActivities = Components.ExportedActivities || []
        const ExportedServices = Components.ExportedServices || []
        const ExportedReceivers = Components.ExportedReceivers || []
        const ExportedProviders = Components.ExportedProviders || []

        fillExport(ExportedActivities, 'activityTest')
        fillExport(ExportedServices, 'serviceTest')
        fillExport(ExportedReceivers, 'broadTest')
        fillExport(ExportedProviders, 'providerTest')


        const Compliance = obj.report.Compliance || {}

        // 危险权限检测
        const DangerousPermissions = Compliance.DangerousPermissions || null
        // 是否包含APK
        const ContainedApkFlag = Compliance.ContainedApkFlag || false
        // 调试证书安全性
        const DebugCertificateFlag = Compliance.DebugCertificateFlag || false
        // 安全性
        const OverallSecurity = Compliance.OverallSecurity || false
        // 漏洞
        const Vuls = Compliance.Vuls || null

        $('#dangerTest').html(DangerousPermissions ? '是' : '否')
        $('#isApkTest').html(ContainedApkFlag ? '是' : '否')
        $('#certTest').html(DebugCertificateFlag ? '非正式证书' : '正式证书')
        $('#saftyTest').html(OverallSecurity ? '安全' : '待提升')
        $('#bugTest').html(Vuls ? '无' : '<label class="red">存在风险</label>')
        $('#virusTest').html('安全') // @todo: 病毒检测-搁置；2023年8月23日16:00:48
    }

    function fillExport(list, id) {
        let cls = ''
        let txt = ''
        if(!list || !list.length) {
            txt = '未导出'
        } else {
            txt = '存在导出'
            cls = 'red'
        }
        $('#' + id).html(txt)
        $('#' + id).removeClass().addClass(cls)
    }

    // iOS数据
    function fillIpa() {
        $('#ipa').show()

        const json = JSON.parse(app.ext2)
        var obj = null
        if(Object.prototype.toString.call(json) === '[object Array]') {
            obj = json[0]
        } else {
            obj = json
        }
        const Vuls = obj.report.Vuls || {}
        console.info('Vuls', Vuls)

        const items = []
        loopVuls(items, Vuls)
        console.info('items:', items)

        countVuls(items)
    }

    function loopVuls(items, Vuls) {
        Object.keys(Vuls).forEach(key => {
            const arr = Vuls[key]
            arr.forEach(obj => {
                if(obj) {
                    Object.keys(obj).forEach(key => {
                        const o = obj[key]
                        if(o) {
                            items.push(o)
                        }
                    })
                }
            })
        })
    }

    function countVuls(items) {
        // level: 1高；2中；3低
        let itemTotal = items.length
        let item1 = 0
        let item2 = 0
        let item3 = 0

        let unSafety1 = 0
        let unSafety2 = 0
        let unSafety3 = 0

        let risk1 = 0
        let risk2 = 0
        let risk3 = 0

        items.forEach(item => {
            const level = item.level
            const safety = item.safety
            const details = item.details || []
            const detailsLen = details.length

            if(level === 1) {
                item1++;
                !safety && unSafety1++
                detailsLen && risk1++
            } else if(level === 2) {
                item2++;
                !safety && unSafety2++
                detailsLen && risk2++
            } else  {
                item3++
                !safety && unSafety3++
                detailsLen && risk3++
            }
        })

        const obj = {
            itemTotal: itemTotal,
            item1: item1,
            item2: item2,
            item3: item3,

            unSafetyTotal: unSafety1 + unSafety2 + unSafety3,
            unSafety1: unSafety1,
            unSafety2: unSafety2,
            unSafety3: unSafety3,

            riskTotal: risk1 + risk2 + risk3,
            risk1: risk1,
            risk2: risk2,
            risk3: risk3,
        }

        if(obj.riskTotal > 0) {
            $('#ipaTip').show()
        } else {
            $('#ipaTip').hide()
        }


        Object.keys(obj).forEach(key => {
            $('#'+key).html(obj[key])
        })
    }
</script>
</html>